package org.i1510.spider.utils.spiderExt.router;

import java.util.List;
import java.util.Map;

import org.i1510.common.utils.StringUtils;
import org.i1510.common.utils.sqliteJdbc.DbUtils;
import org.i1510.spider.bean.SysSpiderRuleBean;

/**
 * @author Administrator
 *
 */
public class HtmlStore {

	/**
	*@Author Rambo
	*@Desc：保存http://caibaojian.com/c/code 的数据列表
	*@param list
	*@return TODO
	*@Version  HtmlStore.java,v 1.1 2014-11-13 下午2:31:22 
	*/
	public boolean saveCBJ(List<Map> list){
		String[] sqls = new String[list.size()];
		// 存储目标数据到数据存储（如DB）、存储已爬取的Url到VisitedUrlQueue
		for (int i = 0 ;i < list.size(); i++) {
			Map map = (Map) list.get(i);			
			sqls[i] = "insert into job_caibaojian values('"
					+StringUtils.object2string(map.get("title"), "").replace("'", "''")+"','"
					+StringUtils.object2string(map.get("href"), "").replace("'", "''")+"','"
					+"jquery;html;css','"
					+"');";
			System.out.println("执行采集sql-insert："+sqls[i]);
		}

		DbUtils db = new DbUtils();			
		return db.tranExecSQL(sqls);
	}
	/**
	*@Author Rambo
	*@Desc：保存http://caibaojian.com/c/code 的数据列表明细数据
	*@param list
	*@param sysSpiderRuleBean
	*@return TODO
	*@Version  HtmlStore.java,v 1.1 2014-11-13 下午3:16:32 
	*/
	public boolean saveCBJ_dt(List<Map> list,SysSpiderRuleBean sysSpiderRuleBean){
		Map map = list.get(0);
		String sql = "";
		// 存储目标数据到数据存储（如DB）、存储已爬取的Url到VisitedUrlQueue
			sql = "insert into job_caibaojian_dt values(?,?,?,?,?,?);";
			Object[] o = new Object[6];
			o[0] = sysSpiderRuleBean.getValue();
			o[1] = sysSpiderRuleBean.getUrl();
			o[2] = sysSpiderRuleBean.getKey();
			o[3] = "";
			o[4] = map.get("descs");
			o[5] = map.get("title");

		DbUtils db = new DbUtils();
		System.out.println("执行采集sql-insert-dt："+sql);
		db.executeUpdate(sql, o);
		
		DbUtils dbx = new DbUtils();
		sql = "update  job_caibaojian set isFlag = 'X' where title = ? and href = ? and tag = ?";
		Object[] ox = new Object[3];
		ox[0] = sysSpiderRuleBean.getValue();
		ox[1] = sysSpiderRuleBean.getUrl();
		ox[2] = sysSpiderRuleBean.getKey();
		System.out.println("执行采集sql-update："+sql);
		if(dbx.executeUpdate(sql, ox) > 0){
			return true;
		}else{
			return false;
		}
	}

}
